﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Composite.Data;

public partial class Admin_LCASystem_Controls_TransportBModal : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public void RefreshComponents()
    {
        using (DataConnection conn = new DataConnection())
        {
            var vehicles = from v in conn.Get<LCA.Data.HeavyVehicle>()
                           select new
                           {
                               Id = v.Id,
                               Name = v.Name + " - " + v.FullLoad + " ton "+v.PercentLoad+" % Loading"
                           };
            vehicles = vehicles.OrderBy(x => x.Name);
            ddlVehicle.DataSource = vehicles;
            ddlVehicle.DataBind();

            // Only UnitGroup = 'Length'
            var units = from u in conn.Get<LCA.Data.Unit>()
                        join uc in conn.Get<LCA.Data.UnitGroup>() on u.UnitGroup equals uc.Id
                        where uc.Id == Guid.Parse("FCE9D31B-685E-437C-A019-B046B79794C8")
                        select new
                        {
                            Id = u.Id,
                            Name = uc.Name + " - " + u.Name
                        };

            units = units.OrderBy(x => x.Name);

            ddlDistanceUnit.DataSource = units;
            ddlDistanceUnit.DataBind();
            // Default: km
            // ddlDistanceUnit.SelectedValue = "0440A2E0-AD6A-4EDB-99B4-C6CFBFA12409";

            // Only UnitGroup = 'Mass'
            var kgUnits = from u in conn.Get<LCA.Data.Unit>()
                        join uc in conn.Get<LCA.Data.UnitGroup>() on u.UnitGroup equals uc.Id
                          where uc.Id == Guid.Parse("5D2525E1-FC60-4D2A-8AA6-CEA10570CA7E")
                        select new
                        {
                            Id = u.Id,
                            Name = uc.Name + " - " + u.Name
                        };

            kgUnits = kgUnits.OrderBy(x => x.Name);

            ddlKgLoadUnit.DataSource = kgUnits;
            ddlKgLoadUnit.DataBind();
            // Default: ton
            // ddlKgLoadUnit.SelectedValue = "5F10554D-8E05-4845-86F1-FB858B6FBFB9";

        }
    }
}